﻿Imports System.Data.SqlClient
Public Class clsSECTOR
    Private mstrID_SECTOR As String
    Private mstrCOD_SECTOR As String
    Private mstrNOMBRE_EMPRESA As String

    Public Property ID_SECTOR() As String
        Get
            Return mstrID_SECTOR
        End Get
        Set(ByVal value As String)
            mstrID_SECTOR = value
        End Set
    End Property
    Public Property COD_SECTOR() As String
        Get
            Return mstrCOD_SECTOR
        End Get
        Set(ByVal value As String)
            mstrCOD_SECTOR = value
        End Set
    End Property
    Public Property NOMBRE_EMPRESA() As String
        Get
            Return mstrNOMBRE_EMPRESA
        End Get
        Set(ByVal value As String)
            mstrNOMBRE_EMPRESA = value
        End Set
    End Property
    Public Sub New()
        mstrID_SECTOR = ""
        mstrCOD_SECTOR = ""
        mstrNOMBRE_EMPRESA = ""

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into SECTOR (" & _
                            "ID_SECTOR," & _
                            "COD_SECTOR," & _
                            "NOMBRE_EMPRESA)" & _
                            "VALUES (" & _
                            "SUBSTRING(@ID_SECTOR,1,100)," & _
                            "SUBSTRING(@COD_SECTOR,1,100)," & _
                            "SUBSTRING(@NOMBRE_EMPRESA,1,100))"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = OptocontrolConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("ID_SECTOR", mstrID_SECTOR)
        Command.Parameters.AddWithValue("COD_SECTOR", mstrCOD_SECTOR)
        Command.Parameters.AddWithValue("NOMBRE_EMPRESA", mstrNOMBRE_EMPRESA)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de sector", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = OptocontrolConnection
        strSqlQry = "Update SECTOR Set " & _
                    "COD_SECTOR=SUBSTRING(@COD_SECTOR,1,100)," & _
                    "NOMBRE_EMPRESA=SUBSTRING(@NOMBRE_EMPRESA,1,100) " & _
                    "Where ID_SECTOR=@ID_SECTOR"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("ID_SECTOR", mstrID_SECTOR)
        Command.Parameters.AddWithValue("COD_SECTOR", mstrCOD_SECTOR)
        Command.Parameters.AddWithValue("NOMBRE_EMPRESA", mstrNOMBRE_EMPRESA)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el sector ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If





    End Sub
End Class
